package com.company;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MathDouble {
    public static void main(String[] args) throws ParseException {
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date startTime1 = dateFormat.parse("2020-05-21 10:59:20");
//        Date endTime1 = dateFormat.parse("2020-05-22 08:30:00");
//        double l2 = (double) (startTime1.getTime() - endTime1.getTime());
//        System.out.println();
//        long l = endTime1.getTime() - startTime1.getTime();
//        System.out.println(l);
//
//        Date startTime2 = dateFormat.parse("2020-06-11 10:51:36");
//        Date endTime2 = dateFormat.parse("2020-06-12 08:30:00");
//        long l1 = endTime2.getTime() - startTime2.getTime();
//        System.out.println(l1);
//
//        long i = 77440;
//        double v = (Math.abs(l) / (1000 * 60 * 60 * 24));
//        double v1 = ((double) l1 / (1000 * 60 * 60 * 24));
//        System.out.println(v);
//        System.out.println(v1);

        MathDouble mathDouble = new MathDouble();
        List<TimeClazz> collect = mathDouble.instList();
        double v2 = collect.stream().mapToDouble(s -> {
            Date endTime = s.getEndTime();
            Date startTime = s.getStartTime();
            return Math.abs((double)(startTime.getTime() - endTime.getTime())) / (1000 * 60 * 60 * 24);
        }).average().orElse(0.00D);
        System.out.println(String.format("%.2f", v2));
//        return String.format("%.2f", v);


    }

    public List<TimeClazz> instList() throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<TimeClazz> list = new ArrayList<>();
        TimeClazz timeClazz = new TimeClazz();
        timeClazz.setStartTime(dateFormat.parse("2020-05-21 10:59:20"));
        timeClazz.setEndTime(dateFormat.parse("2020-05-22 08:30:00"));
        list.add(timeClazz);

        TimeClazz timeClazz1 = new TimeClazz();
        timeClazz1.setStartTime(dateFormat.parse("2020-06-11 10:51:36"));
        timeClazz1.setEndTime(dateFormat.parse("2020-06-12 08:30:00"));
        list.add(timeClazz1);
        return list;
    }

    public class TimeClazz {
        private Date startTime;
        private Date endTime;

        public Date getStartTime() {
            return startTime;
        }

        public void setStartTime(Date startTime) {
            this.startTime = startTime;
        }

        public Date getEndTime() {
            return endTime;
        }

        public void setEndTime(Date endTime) {
            this.endTime = endTime;
        }
    }
}
